package com.ywjh.inter.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import com.ywjh.inter.entity.DocGroupEntity;

public class DocGroupDAO {
	public List<DocGroupEntity> list(Connection conn) throws SQLException {
		List<DocGroupEntity> list = new LinkedList<DocGroupEntity>();
		// PreparedStatement ps = conn.prepareStatement("select * from doc_group where
		// status=1");
		PreparedStatement ps = conn.prepareStatement(
				"select * from doc_group a where a.status=1 and EXISTS (select doc_group_id from doc_group_disease b where a.id=b.doc_group_id)");
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DocGroupEntity e = new DocGroupEntity();
			e.setAdd_admin_id(rs.getInt("add_admin_id"));
			e.setAdd_time(rs.getTimestamp("add_time"));
			e.setId(rs.getInt("id"));
			e.setName(rs.getString("name"));
			e.setStatus(rs.getInt("status"));
			list.add(e);
		}
		return list;
	}
}
